<?php


namespace App\Traits;


use App\Models\CustomerAssignment;
use App\Models\Followup;
use App\Models\Property;
use Dcat\Admin\Grid;

trait CustomerCard
{
    //关联房源
    public static function hasCustomerPropertyCard($customer_id)
    {
        return Grid::make(Property::with(['community']), function (Grid $grid) use ($customer_id){

            $grid->column('community.community_name','楼盘');
            $grid->column('building_number','楼座');
            $grid->column('unit_number','单元');
            $grid->column('room_number','门牌');

            $grid->model()->where('customer_id',$customer_id)->orderBy('id','desc');

            $grid->disableToolbar();
            $grid->disableRowSelector();
            $grid->disableCreateButton();
            $grid->disableActions();
            $grid->disablePagination();

        });
    }


    //客户跟进记录
    public static function hasCustomerFollowupCard($customer_id)
    {
        return Grid::make(Followup::with('user'), function (Grid $grid) use ($customer_id){

            $grid->column('user.name','跟进人');
            $grid->column('content','跟进内容');
            $grid->column('created_at','跟进时间');

            $grid->model()->where('customer_id',$customer_id)->orderBy('id','desc');

            $grid->disableToolbar();
            $grid->disableRowSelector();
            $grid->disableCreateButton();
            $grid->disableActions();
            $grid->disablePagination();

        });
    }

    //客户流转记录
    public static function hasCustomerAssignmentCard($customer_id)
    {
        return Grid::make(CustomerAssignment::with(['fromUser','toUser']), function (Grid $grid) use ($customer_id){

            $grid->column('fromUser.name','原归属人');
            $grid->column('toUser.name','新归属人');
            $grid->column('type','流转类型')->using(CustomerAssignment::TYPE);
            $grid->column('reason','流转原因');
            $grid->column('created_at','流转时间');

            $grid->model()->where('customer_id',$customer_id)->orderBy('id','desc');

            $grid->disableToolbar();
            $grid->disableRowSelector();
            $grid->disableCreateButton();
            $grid->disableActions();
            $grid->disablePagination();

        });
    }

}
